package com.mttang.adv.web.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.net.ftp.FTPClient;


public class AdvFileFtpUtil {
    private FTPClient ftpClient;
    
    private String host;
    
    private String post;
    
    private String username;
    
    private String password;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public FTPClient getFtpClient() {
        return ftpClient;
    }

    
    public void setFtpClient(FTPClient ftpClient) {
        this.ftpClient = ftpClient;
    }

    public boolean upload(File file){
        boolean isUpload = false; 
        InputStream in = null; 
        if (file != null) { 
            try { 
                in = new FileInputStream(file); 
                isUpload = ftpClient.appendFile(file.getName(), in);
                
            } catch (IOException e) { 
                return false; 
            } finally { 
                if (in != null) { 
                    try { 
                        in.close(); 
                    } catch (IOException e) { 
                        return false; 
                    } 
                } 
            } 
        } else { 
            return false; 
        } 
        return isUpload; 
    }
}
